package algorithm.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: algorithm.easy
 * @Author: 江岸
 * @CreateTime: 2021-02-12 11:21
 * @Description: 杨辉三角
 */
public class GetRow119 {
    public static void main(String[] args) {
//        int k = 4;
//        int[][] arr = new int[k][k];
//        for (int i=0;i<k;i++){
//            for (int j=0;j<=i;j++){
//                if (j==0||j==i){
//                    arr[i][j]=1;
//                    continue;
//                }
//                arr[i][j] = arr[i-1][j-1]+arr[i-1][j];
//            }
//        }
//        for (int i=0;i<k;i++){
//            for (int j=0;j<=i;j++){
//                System.out.print(arr[i][j]+" ");
//            }
//            System.out.println();
//        }
        getRow(3);
    }

    public static List<Integer> getRow(int rowIndex) {
        int[][] arr = new int[rowIndex+1][rowIndex+1];
        for (int i=0;i<rowIndex+1;i++){
            for (int j=0;j<=i;j++){
                if (j==0||j==i){
                    arr[i][j]=1;
                    continue;
                }
                arr[i][j] = arr[i-1][j-1]+arr[i-1][j];
            }
        }
        ArrayList<Integer> integers = new ArrayList<>();
        for (int j=0;j<=rowIndex;j++){
            integers.add(arr[rowIndex][j]);
        }
        return integers;
    }
}
